function menuFunction(){
	this.goodsMgrTree =  [
        { funId: "goodsList", name: "商品列表", mgrText: "商品管理"},
        { funId: "addGoods", name: "添加商品", mgrText: "商品管理"},
        { funId: "goodsType", name: "商品类型", mgrText: "商品管理"},
        { funId: "goodsGroup", name: "商品分类", mgrText: "商品管理"},
        { funId: "goodsBrand", name: "商品品牌", mgrText: "商品管理"},
        { funId: "goodsTrash", name: "商品回收站", mgrText: "商品管理"}
    ];
	 
	this.ordersMgrTree =  [
        { funId: "orderList", name: "订单列表", mgrText: "订单管理"},
        { funId: "orderQuery", name: "订单查询", mgrText: "订单管理"},
        { funId: "addOrder", name: "添加订单", mgrText: "订单管理"},
        { funId: "mergeOrder", name: "合并订单", mgrText: "订单管理"},
        { funId: "printOrder", name: "订单打印 ", mgrText: "订单管理"}
    ];
	 
	this.membersMgrTree =  [
        { funId: "memberList", name: "会员列表", mgrText: "会员管理"},
        { funId: "memberMessages", name: "会员留言", mgrText: "会员管理"},
        { funId: "addMember", name: "添加会员", mgrText: "会员管理"},
        { funId: "memberComments", name: "用户评论", mgrText: "会员管理"}
    ];
	        
    this.articlesMgrTree =  [
        { funId: "articlesList", name: "文字列表" ,mgrText: "文章管理"},
        { funId: "articlesSort", name: "文章分类 " ,mgrText: "文章管理"}
    ];
    
    this.webMgrTree = [
        { funId: "navbarConfig", name: "导航栏配置", mgrText: "网站管理"},
        { funId: "webResource", name: "网站资源", mgrText: "网站管理"},
        { funId: "webTemplate", name: "网站模板", mgrText: "网站管理"}
    ];
    
    this.systemMgrTree =  [
    	{ funId: "systemLog", name: "系统日志", mgrText: "系统管理"},
    	{ funId: "orderLog", name: "订单日志", mgrText: "系统管理"},
        { funId: "supplierList", name: "供货商列表", mgrText: "系统管理"},
        { funId: "agentList", name: "代理商列表", mgrText: "系统管理"},
        { funId: "regionList", name: "区域列表", mgrText: "系统管理"},
        { funId: "memberDataItem", name: "会员资料项", mgrText: "系统管理"},
        { funId: "passwordQuestion", name: "密保问题", mgrText: "系统管理"}
    ];
}

var menuObj	= new menuFunction();

/**
 * 左侧树形菜单点击监听事件
 * @param {} e
 */
function menuListTreeClick(e){
	var menuListTree = mini.get("menu-lists-tree");
	var node = e.node;
	var nodeChildren = node.children;
	
	if (nodeChildren != null && nodeChildren != "undefined" && nodeChildren.length > 0) {
		if(menuListTree.isExpandedNode(node)){
			menuListTree.collapseNode(node);
		}else{
			menuListTree.expandNode(node);
		}
    }else{
    	createTreeNodeTab(menuListTree, node);
    }
};

/**
 * 树形节点生成选显卡
 * @param {} menuListTree
 * @param {} node
 */
function createTreeNodeTab(menuListTree, node) {
	var menuTabs = mini.get("menu-tabs-div");
	var id = node.funId;
	switch(id){ 
		case 'goodsList':
			openTreeNodeTab(menuListTree, node, "../web/goodsMgr/" + id + ".jsp");
			break;
		case 'addGoods':
			openTreeNodeTab(menuListTree, node, "../web/goodsMgr/" + id + ".jsp");
			break;
		case 'goodsType':
			openTreeNodeTab(menuListTree, node, "../web/goodsMgr/" + id + ".jsp");
			break;
		case 'goodsGroup':
			openTreeNodeTab(menuListTree, node, "../web/goodsMgr/" + id + ".jsp");
			break;
		case 'goodsBrand':
			openTreeNodeTab(menuListTree, node, "../web/goodsMgr/" + id + ".jsp");
			break;
		case 'goodsTrash':
			openTreeNodeTab(menuListTree, node, "../web/goodsMgr/" + id + ".jsp");
			break;
		case 'orderList':
			openTreeNodeTab(menuListTree, node, "../web/ordersMgr/" + id + ".jsp");
			break;
		case 'orderQuery':
			openTreeNodeTab(menuListTree, node, "../web/ordersMgr/" + id + ".jsp");
			break;
		case 'addOrder':
			openTreeNodeTab(menuListTree, node, "../web/ordersMgr/" + id + ".jsp");
			break;
		case 'mergeOrder':
			openTreeNodeTab(menuListTree, node, "../web/ordersMgr/" + id + ".jsp");
			break;
		case 'printOrder':
			openTreeNodeTab(menuListTree, node, "../web/ordersMgr/" + id + ".jsp");
			break;
		case 'memberList':
			openTreeNodeTab(menuListTree, node, "../web/membersMgr/" + id + ".jsp");
			break;
		case 'memberMessages':
			openTreeNodeTab(menuListTree, node, "../web/membersMgr/" + id + ".jsp");
			break;
		case 'addMember':
			openTreeNodeTab(menuListTree, node, "../web/membersMgr/" + id + ".jsp");
			break;
		case 'memberComments':
			openTreeNodeTab(menuListTree, node, "../web/membersMgr/" + id + ".jsp");
			break;
		case 'articlesList':
			openTreeNodeTab(menuListTree, node, "../web/articlesMgr/" + id + ".jsp");
			break;
		case 'articlesSort':
			openTreeNodeTab(menuListTree, node, "../web/articlesMgr/" + id + ".jsp");
			break;
		case 'navbarConfig':
			openTreeNodeTab(menuListTree, node, "../web/webMgr/" + id + ".jsp");
			break;
		case 'webResource':
			openTreeNodeTab(menuListTree, node, "../web/webMgr/" + id + ".jsp");
			break;
		case 'webTemplate':
			openTreeNodeTab(menuListTree, node, "../web/webMgr/" + id + ".jsp");
			break;
		case 'systemLog':
			openTreeNodeTab(menuListTree, node, "../web/systemMgr/" + id + ".jsp");
			break;
		case 'orderLog':
			openTreeNodeTab(menuListTree, node, "../web/systemMgr/" + id + ".jsp");
			break;
		case 'supplierList':
			openTreeNodeTab(menuListTree, node, "../web/systemMgr/" + id + ".jsp");
			break;
		case 'agentList':
			openTreeNodeTab(menuListTree, node, "../web/systemMgr/" + id + ".jsp");
			break;
		case 'regionList':
			openTreeNodeTab(menuListTree, node, "../web/systemMgr/" + id + ".jsp");
			break;
		case 'memberDataItem':
			openTreeNodeTab(menuListTree, node, "../web/systemMgr/" + id + ".jsp");
			break;
		case 'passwordQuestion':
			openTreeNodeTab(menuListTree, node, "../web/systemMgr/" + id + ".jsp");
			break;
		default:
			break;
	}
}

/**
 * 打开或创建新选项卡
 * @param {} menuListTree
 * @param {} node
 * @param {} actionUrl
 */
function openTreeNodeTab(menuListTree, node ,actionUrl){
	var menuTabs = mini.get("menu-tabs-div");
    var id = node.funId;
    var mgrText = node.mgrText;
    
    var tab = menuTabs.getTab(id);
    if (!tab) {
    	tab = findSiblingTreeNodeTab(menuTabs, menuListTree.getRootNode().children);
    	if (!tab) {
    		tab = {};
    		menuTabs.addTab(tab);
    	}
    	menuTabs.updateTab(tab, 
    		{
    		 	name: id, 
    		 	title: mgrText + "-[<span style='color:BLUE;'>" + node.name + "</span>]",
    		 	showCloseButton: true, 
    		 	url:actionUrl
    		}
    	);
    	menuTabs.reloadTab(tab);
    }
    menuTabs.activeTab(tab);    
}

/**
 * 查找同级树节点并返回同级节点对象
 * tabIndex = menuTabs.tabs.indexOf(tab)；获得指定tab的索引
 * @param {} menuTabs
 * @param {} childNodes
 * @return {}
 */
function findSiblingTreeNodeTab(menuTabs, childNodes){
	if(childNodes != null && childNodes.length > 0){
		for (var i = 0; i < childNodes.length; i++) {
			var tab = menuTabs.getTab(childNodes[i].funId);
			if(tab != null){
				return tab;
			}
		}
	}
	return null;
}
